package com.bmps.springcloud.insuredmicroservice.service.amnt.strategy;

import com.bmps.springcloud.common.utils.DateUtil;
import com.bmps.springcloud.insuredmicroservice.constant.accept.AcceptConstant;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.InsurantModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.ProductModel;
import com.bmps.springcloud.insuredmicroservice.model.accept.resquest.RequestModel;
import com.bmps.springcloud.insuredmicroservice.model.trail.TrialPersonModel;
import com.bmps.springcloud.insuredmicroservice.service.RedisService;
import com.bmps.springcloud.insuredmicroservice.util.accept.AcceptUtil;
import com.bmps.springcloud.insuredmicroservice.util.trial.TrialUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;

/**
 * description:
 *
 * @author jackdaw
 * @date 2020-06-16 17:09
 */
public class Net006AmntStrategy implements AmntStrategy {

    private static final Logger logger = LoggerFactory.getLogger(Net006AmntStrategy.class);

    @Override
    public TrialPersonModel amntTrialCalculation(ProductModel productModel, RequestModel requestModel, RedisService redisService) {
        List<InsurantModel> insurantModelList = requestModel.getCustInfo().getInsurants().getInsurant();
        InsurantModel insurantModel = AcceptUtil.getInsurantModelBySeq(productModel.getProdInsSeq(), insurantModelList);
        TrialPersonModel trialPersonModel = new TrialPersonModel();
        String riskCode = productModel.getProdCode();

        trialPersonModel.setRiskCode(riskCode);
        trialPersonModel.setPrem(productModel.getPrem());
        trialPersonModel.setPayEndYear(productModel.getPayYear());
        trialPersonModel.setAppAge(DateUtil.getYears(insurantModel.getBirthday(), requestModel.getPolicyInfo().getPolApplyDate()));
        trialPersonModel.setSex(insurantModel.getSex());

        trialPersonModel = redisService.getCalculateMode(trialPersonModel, AcceptConstant.CALCULATION_TYPE_P);
        return trialPersonModel;

    }
}
